package com.meritdata.cloud.data.standard.quality.controller;

import com.meritdata.cloud.data.base.Page;
import com.meritdata.cloud.data.standard.quality.entity.TdDataQualityRule;
import com.meritdata.cloud.data.standard.quality.service.QualityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.Map;
import java.util.UUID;
//质量规则

@RequestMapping("/api/standard/quality")
@Controller
public class QualityController {

	@Autowired
	private QualityService service;

	@RequestMapping("/add")
	@ResponseBody
	public TdDataQualityRule add(@RequestParam String name, @RequestParam int conditionType,
								 @RequestParam String description, @RequestParam String conditionExp){
		TdDataQualityRule ds = new TdDataQualityRule();
		ds.setName(name);
		ds.setConditionType(conditionType);
		ds.setDescription(description);
		ds.setConditionExp(conditionExp);
		ds.setType("系统模板");
		ds.setPublishState(0);
		ds.setApplyColumnType("字段级");
		ds.setCreateTime(new Date());
		ds.setUpdateTime(new Date());
		service.add(ds);
		return ds;
	}

	@RequestMapping("/page")
	@ResponseBody
	public Page<TdDataQualityRule> page(@RequestParam Map<String,Object> param){

		return service.page(param);
	}
	@RequestMapping("/del")
	@ResponseBody
	public Boolean  del(@RequestParam String id){
		return service.del(id);
	}
	@RequestMapping("/update")
	@ResponseBody
	public Boolean update(@RequestParam String id, @RequestParam String name, @RequestParam int conditionType,
						  @RequestParam String description, @RequestParam String conditionExp){
		return service.update(id,name,conditionExp,conditionType,description);
	}
	@RequestMapping(value = "/update/state")
	@ResponseBody
	public Boolean  updateState(@RequestParam String ids,@RequestParam Integer state){
		return service.updateState(ids,state);
	}

}